﻿using PureMVC.Interfaces;
using Rail.Commons;
using Rail.Demo.Viewer;
using System;
using System.Collections.Generic;
using System.Data;

namespace Rail.Demo.Viewer
{
    public class DemoFormMediator2: PureMVC.Patterns.Mediator, IMediator
    {
        DemoForm2 m_DemoForm;
        public new const string NAME = "DemoFormMediator2";
        public DemoFormMediator2(DemoForm2 viewComponent)
               : base(NAME, viewComponent)
        {
            m_DemoForm = viewComponent;
            m_DemoForm.Value1.ValueChanged += ValueChanged;
            m_DemoForm.Value2.ValueChanged += ValueChanged;

            m_DemoForm.ButtonQuery.Click += ButtonQuery_Click;
        }

        public override IList<string> ListNotificationInterests()
        {
            IList<string> list = new List<string>();
            list.Add(Messages.SHOW_QUERY_TEST);
            return list;
        }
        public override void HandleNotification(INotification note)
        {
            switch (note.Name)
            {
                //将查询的结果显示到界面上
                case Messages.SHOW_QUERY_TEST:
                    this.m_DemoForm.DataGridView.DataSource = null;
                    this.m_DemoForm.DataGridView.DataSource = note.Body as DataTable;
                    this.m_DemoForm.DataGridView.Refresh();
                    break;
            }
        }
        private void ButtonQuery_Click(object sender, EventArgs e)
        {
            SendNotification("QueryTableDemoCommand");
        }

        private void ValueChanged(object sender, EventArgs e)
        {
            m_DemoForm.Result.Text = (m_DemoForm.Value1.Value - m_DemoForm.Value2.Value).ToString();
            SendNotification(Rail.Commons.Messages.SHOWINFOMESSAGE,"计算结果为：" + m_DemoForm.Result.Text);
        }
    }
}
